
LodeCheerMap();

//处理步数函数,x,y反着写是有原因的,无需更改
function manPosition(y,x) {
	var data = x*100+y;
	data = '{"result":"'+data+'"}';
	add(x,y,"blackCheer");
	$.ajax({
		async: false,
		data: data,
		type: "post",
		url: serverIpAddress+"CodeGame/ManAndRobot",
		contentType: "application/json;charset=utf-8",
		dataType: "json",
		success:function (position) {
			data = position.result;
		}
	});
	if(data === "error") {
		swal("错误", "你对手的代码编译错误", "error");
		$("button").click(function () {
			window.location = "RobotLode.html";
		});
	} else if(data === "lose") {
		swal("失败","你的对手太厉害了，你输了","error");
		$("button").click(function () {
			window.location = "RobotLode.html";
		});
	} else if(data === "win") {
		swal("胜利","你太厉害了!(●—●)","success");
		$("button").click(function () {
			window.location = "RobotLode.html";
		});
	} else {
		x = Math.floor(Number(data) / 100);
		y = Number(data) % 100;
		add(x, y, "whiteCheer");
	}
}

function LodeCheerMap() {

	var	quyu = "",
		quyu1 = "<area shape='rect' coords='",
		quyu2 = ",",
		quyu3 ="' onClick='manPosition(",
		quyu4 = ");'>";
	var qunum = 4;
//4,4,30,30 区块坐标
	for(var yzhou = 0; yzhou < 15; yzhou++) {
		for(var xzhou = 0; xzhou < 15; xzhou++) {
			var att = qunum + xzhou*26, btt = qunum + yzhou*26, ctt = att + 26, dtt = btt + 26;
			quyu = quyu + quyu1 + att.toString() + quyu2 + btt.toString() + quyu2 + ctt.toString() + quyu2 + dtt.toString() + quyu3 + xzhou.toString() + quyu2 + yzhou.toString() + quyu4;
		}
	}
	var matt = document.getElementById("haha");
	matt.innerHTML = quyu;
	//***end ---15*15区块代码
}

//在指定位置添加棋子
function add(x,y,jur) {
	var cheer = "",
		blacheer = "<p><img src='backstage/img/blackCheer.png' width='28' height='27' style='position: absolute; left:",
		blacheer2 = "px; top: ",
		blacheer3 = "px;'></p>",
		whcheer = "<p><img src='backstage/img/whiteCheer.png' width='38' height='36' style='position: absolute; left:",
		whcheer2 = "px; top: ",
		whcheer3 = "px;'></p>";
	var blanum1 = 4, blanum2 = 4, whinum1 = 0, whinum2 = 0;

	var aq = document.getElementById("mean");

	var a = 0, b = 0;
	if(jur === "whiteCheer") {
		a = whinum1 + x*26;
		b = whinum2 + y*26;
		cheer = cheer + whcheer + b.toString() + whcheer2 + a.toString() + whcheer3;

	}
	else {
		a = blanum1 + x*26;
		b = blanum2 + y*26;
		cheer = cheer + blacheer + b.toString() + blacheer2 + a.toString() + blacheer3;
	}
	aq.innerHTML += cheer;
}


//以下为时间计时器处理代码
var Inter=setInterval("mytime()",1000);
var hour=0,min=0,sec=0;
function mytime() {
	sec++;
	if(sec==60) {
		sec=0;
		min++;
	}
	if(min==60) {
		min=0;
		hour++;
	}
	if(hour==60) {
		alert("游戏时间过长，重新开始比赛");
		window.location.reload();
	}

	var m1="",s1="",h1="";
	if(sec<10) {
		s1="0"+sec;
	}
	else {
		s1=sec;
	}
	if(min<10) {
		m1="0"+min;
	}
	else {
		m1=min;
	}
	if(hour<10) {
		h1="0"+hour;
	}
	else {
		h1=hour;
	}
	$("#time").html(h1+"："+m1+"："+s1);

}
